package com.whj.wkpt.mapper;

import com.whj.wkpt.entity.Task;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TaskMapper {
    
    Task findById(Long taskId);
    
    @Insert("INSERT INTO tasks(employer_id, title, description, budget, task_status, publish_date, create_time, update_time) " +
            "VALUES(#{employerId}, #{title}, #{description}, #{budget}, #{taskStatus}, #{publishDate}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "taskId")
    int insert(Task task);
    
    @Update("UPDATE tasks SET employer_id=#{employerId}, title=#{title}, description=#{description}, " +
            "budget=#{budget}, task_status=#{taskStatus}, publish_date=#{publishDate}, update_time=#{updateTime} " +
            "WHERE task_id=#{taskId}")
    int update(Task task);
    
    @Delete("DELETE FROM tasks WHERE task_id = #{taskId}")
    int deleteById(Long taskId);
    
    List<Task> findAll();
    
    List<Task> findByEmployerId(Long employerId);
    
    List<Task> findByTitleContaining(String title);
    
    List<Task> findByTaskStatus(String taskStatus);
    
    List<Task> findByEmployerIdAndTitleContaining(Long employerId, String title);
    
    List<Task> findByEmployerIdAndTaskStatus(Long employerId, String taskStatus);
    
    List<Task> findByEmployerIdAndTitleContainingAndTaskStatus(Long employerId, String title, String taskStatus);
    
    List<Task> findByIds(List<Long> taskIds);
    
    // 分页查询相关方法
    List<Task> findAllWithPagination(@Param("offset") int offset, @Param("limit") int limit);
    
    List<Task> findByTitleContainingWithPagination(@Param("title") String title, @Param("offset") int offset, @Param("limit") int limit);
    
    List<Task> findByTaskStatusWithPagination(@Param("taskStatus") String taskStatus, @Param("offset") int offset, @Param("limit") int limit);
    
    List<Task> findByTitleContainingAndTaskStatusWithPagination(@Param("title") String title, @Param("taskStatus") String taskStatus, @Param("offset") int offset, @Param("limit") int limit);
    
    int countAll();
    
    int countByTitleContaining(@Param("title") String title);
    
    int countByTaskStatus(@Param("taskStatus") String taskStatus);
    
    int countByTitleContainingAndTaskStatus(@Param("title") String title, @Param("taskStatus") String taskStatus);
}